<template>
  <view class="container">
    <uni-forms :modelValue="form" label-width='200rpx'>
      <uni-forms-item label="起始年份" name="startYear">
        <uni-data-select v-model="form.startYear" :localdata="range" @change="change"></uni-data-select>
      </uni-forms-item>
      <uni-forms-item label="申领金额" name="amount">
        <uni-easyinput type="number" v-model.number="form.amount" placeholder="请输入申领金额"></uni-easyinput>
      </uni-forms-item>
      <uni-forms-item label="申领次数" name="times">
        <uni-easyinput type="number" v-model.number="form.times" placeholder="请输入申领金额"/>
      </uni-forms-item>
    </uni-forms>
    <view class="tip">
      <uni-icons type="help" size="20"></uni-icons>
      <text style="font-size: 12px;">自【{{ form.startYear && form.startYear + '年' || '起始年份' }}】1月1日起，【{{
          currentSyr.name
        }}】可于每自然年12月25日（含）向受托人提出书面申请需求，一次性申领不超过 【{{ form.amount || '申领金额' }}】万元（下同），不得重复申领。为避免争议，若【{{
          currentSyr.name
        }}】是在某个自然年（当年）的12月25日（不含）至下一个自然年（次年）的12月25日（含）期间提出的申领，则该次申领应 作为次年的申领，申领次数不超过【{{
          form.times || '申领次数'
        }}】次。如无需填写则选择跳过。
      </text>
    </view>
    <view class="bottom" style="display: flex;justify-content: center">
      <button class="button" type="primary" @click="jump(201)">跳过</button>
      <button class="button" type="primary" @click="submit">下一步</button>
    </view>
  </view>
</template>

<script>
import userInfoMixin from "../../common/js/userInfoMixin";

export default {
  mixins: [userInfoMixin],
  data() {
    return {
      name: '200',
      form: {
        startYear: '',
        amount: '',
        times: '',
        total: 0
      },
      range: [],
    }
  },
  created() {
    this.range = new Array(20).fill(1).map((v, idx) => {
      let now = 2024
      return {
        value: now + idx,
        text: (now + idx) + '年'
      }
    })
    this.getJcrDetail()
  },
  methods: {
    // 获取最新的一次数据，保存起来供后面使用
    getJcrDetail() {
      // 数据库操作
      let db = wx.cloud.database(), that = this
      db.collection('JCRS')
          .where({
            openid: this.currentSyr.openid,
            name: this.currentSyr.name
          }).get({
        success: res => {
          console.log('数据库返回的数据：', res.data)
        }
      })
    },
    change() {

    },
    prevStep() {
    },
    submit() {
      this.submitData({
        key: 'dqsl',
        data: Object.assign({}, this.form, {
          total: this.form.amount * this.form.times
        })
      }, '201')
    },
  }
}
</script>

<style>

</style>
